package service

import (
	"log"
	"prometheus_import_consul/global"
	"prometheus_import_consul/tools"
)

// HostInfo 用于映射YAML文件结构
type HostInfo map[string][]string

// Host 读取并解析host.yaml，然后添加每个主机
func Host() {

	var results HostInfo
	err := tools.ReadJSONFile(global.Config.JsonFile.Hostjson_Path, &results)
	if err != nil {
		log.Fatalf("Error reading adn parsing JSON file: %s,error: %v\n", global.Config.JsonFile.Hostjson_Path, err)
	}
	log.Printf("Success reading and parsing JSON file: %s\n", global.Config.JsonFile.Hostjson_Path)

	for hostIP, info := range results {
		if len(info) >= 3 {
			tools.Add_host(hostIP, info[0], info[1], info[2])
		}
	}
}
